package com.mmlc.inter;

import android.content.Context;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;

import com.androidnetframe.BaseParentActivity;
import com.mmlc.meimei.lichengkongjian.R;
import com.mmlc.utils.ActivityManager;
import com.mmlc.widget.TitleBarView;

public abstract class InterActivity extends BaseParentActivity implements OnClickListener {
    protected String TAG;
    protected Context context;
    protected BaseParentActivity activity;

    protected long lasttime = 0;

    protected boolean avoid() {
        return avoid(700, null);
    }

    protected boolean avoid(String toastStr) {
        return avoid(700, toastStr);
    }

    protected boolean avoid(long period, String toastStr) {
        long currenttime = System.currentTimeMillis();
        if (currenttime - lasttime <= period) {
            if (context != null) {
            }
            return true;
        } else {
            lasttime = currenttime;
        }
        return false;
    }

    protected TitleBarView tb_titleBar;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        ActivityManager.addActivity(this);
        // overridePendingTransition(R.anim.act_leftin, R.anim.act_leftout);
        TAG = this.getClass().getSimpleName();
        activity = this;
        context = getApplicationContext();
        lasttime = System.currentTimeMillis();

        setContentView(initContentView());

        tb_titleBar = (TitleBarView) findViewById(R.id.tb_titleBar);

        initExtra();
        initView();
        initInfo();
        initEvent();
        registerReceiver();
    }

    protected abstract int initContentView();

    protected void initExtra() {
    }

    protected abstract void initView();

    protected void initInfo() {
    }

    /**
     * 初始化事件
     */
    protected void initEvent() {

    }

    @Override
    public void onClick(View view) {
        if (avoid())
            return;
    }

    protected void registerReceiver() {

    }

    protected void unregisterReceiver() {

    }

    @Override
    public void finish() {
        ActivityManager.removeActivity(this.getClass());
        super.finish();

        unregisterReceiver();
    }

}
